# database.py
import platform
from urllib import parse
from sqlalchemy import create_engine
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import sessionmaker

system_type = platform.system()  # 获取系统信息

# 数据库访问地址
HOST = '101.34.210.85'
PORT = 13306
USERNAME = 'root'
PASSWORD = parse.quote_plus('HywNidkmiZYBLswh')
DB = 'yhpc'

MAX_POOL_SIZE = 50  # 设置连接池的最大连接数


DB_URI = f'mysql+pymysql://{USERNAME}:{PASSWORD}@{HOST}:{PORT}/{DB}'

engine = create_engine(DB_URI, pool_pre_ping=True, pool_size=10, max_overflow=50)
SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)

# 数据模型的基类
Base = declarative_base()


def get_db():
    db = SessionLocal()
    try:
        yield db
    finally:
        db.close()
